package game;

import java.awt.event.MouseEvent;

public class ControlMenu extends Menu{
    protected boolean isSetting;
    protected MenuButton inputButton;
    protected KeyValues val;

    public ControlMenu(Menu a) {
        super(a);
        init();
    }

    public ControlMenu(GrandeCanvas c) {
        super(c);
        init();
    }

    public void init(){
        val = new KeyValues();
        elements.add(new MenuButton(this, 450, 200, 275, 50, "Jump: " + val.getKey(getCanvas().moveJump).toUpperCase(), 30, null){
            @Override
            public void clicked(MouseEvent e){
                inputButton = this;
                isSetting = true;
            }
            @Override
            public void keyPress(int keycode){
                isSetting = false;
                this.info = "Jump: " + val.getKey(keycode).toUpperCase();
                getCanvas().moveJump = keycode;
            }
        });
        elements.add(new MenuButton(this, 750, 200, 275, 50, "Strafe Left: " + val.getKey(canvas.moveLeft).toUpperCase(), 30, null){
            @Override
            public void clicked(MouseEvent e){
                inputButton = this;
                isSetting = true;
            }
            @Override
            public void keyPress(int keycode){
                isSetting = false;
                this.info = "Strafe Left: " + val.getKey(keycode).toUpperCase();
                getCanvas().moveLeft = keycode;
            }
        });
        elements.add(new MenuButton(this, 450, 275, 275, 50, "Strafe Right: " + val.getKey(canvas.moveRight).toUpperCase(), 30, null){
            @Override
            public void clicked(MouseEvent e){
                inputButton = this;
                isSetting = true;
            }
            @Override
            public void keyPress(int keycode){
                isSetting = false;
                this.info = "Strafe Right: " + val.getKey(keycode).toUpperCase();
                getCanvas().moveRight = keycode;
            }
        });
        elements.add(new MenuButton(this, 750, 275, 275, 50, "Test: " + val.getKey(canvas.moveJump).toUpperCase(), 30, null){
            @Override
            public void clicked(MouseEvent e){
                inputButton = this;
                isSetting = true;
            }
            @Override
            public void keyPress(int keycode){
                isSetting = false;
                this.info = "Test: " + val.getKey(keycode).toUpperCase();
                getCanvas().moveJump = keycode;
            }
        });
        elements.add(new MenuButton(this, 500, 350, 450, 50, "Back", 30, null){
            @Override
			public void clicked(MouseEvent e){
                if(parent != null){
                    parent.subMenu = null;
                }
            }
        });
        isSetting = false;
    }

    @Override
	public void mousePress(MouseEvent event){
        if(isSetting){
            return;
        }
        for(MenuItem item: elements){
            if(item.contains(event.getX(), event.getY())){
                item.clicked(event);
            }
        }
    }

    @Override
	public void keyPress(int keycode){
        if(isSetting){
            inputButton.keyPress(keycode);
        }
    }
}
